//
//  AlertResultView.m
//  sellHouse
//
//  Created by 李 佳伟 on 2018/11/21.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "AlertResultView.h"
#import "JTCSM.h"
static AlertResultView *single = nil;
static CGFloat backViewHeight = 130;
static CGFloat imagesize = 35;
static CGFloat labelheight = 80;
@interface AlertResultView()
{
    UILabel *titleLabel;
    UIImageView *targetImageV;
}

@end

@implementation AlertResultView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
+ (AlertResultView *)shareSingle
{
    @synchronized(self){
        if(single == nil){
            single =[ [AlertResultView alloc] init];
        }
        
    }
    return single;
}

- (instancetype)init{
    self = [super init];
    if (self) {
        self.frame = CGRectMake(0, 0, KSCREENWidth, KSCREENHeight);
        self.hidden = YES;
        self.userInteractionEnabled = YES;
        self.backgroundColor = RGBACOLOR(0, 0, 0, 0.3);
        CGFloat space = 30;
        UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(space, (KSCREENHeight-backViewHeight)/2-60, KSCREENWidth-space*2, backViewHeight)];
        [df layerWithView:backView radius:4 width:0 color:nil];
        backView.backgroundColor = [UIColor whiteColor];
        [self addSubview:backView];
        
        
        titleLabel = [UILabel initWithFrame:CGRectMake(0, 0, backView.frame.size.width, labelheight) text:@"修改姓名" font:16 textAlignment:NSTextAlignmentCenter texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
        [backView addSubview:titleLabel];
        CGRect rect = [df labelHeightWithContent:titleLabel.text height:labelheight label:titleLabel];
        
        CGFloat imageX = (backView.frame.size.width-rect.size.width-imagesize-10)/2;
        CGFloat imageY = (labelheight-imagesize)/2;
        
        
        targetImageV = [[UIImageView alloc]initWithFrame:CGRectMake(imageX, imageY, imagesize, imagesize)];
        [backView addSubview:targetImageV];
        
        titleLabel.frame = CGRectMake(KVIEW_X(targetImageV)+10, 0, rect.size.width, labelheight);
        
        CGFloat buttonHeight =50;
        UIButton *sureButton = [UIButton buttonWithType:UIButtonTypeCustom];
        sureButton.frame = CGRectMake(0, backViewHeight-buttonHeight, backView.frame.size.width, buttonHeight);
        [sureButton setBackgroundColor:RGBACOLOR(15,166,232,1)];
        [sureButton setTitle:@"关闭" forState:UIControlStateNormal];
        [sureButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
        [backView addSubview:sureButton];
        [sureButton addTarget:self action:@selector(hidden) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

- (void)showWithsuccess:(BOOL)success{
    self.hidden = NO;
    if(success){
        titleLabel.text = @"修改成功";
        targetImageV.image = [UIImage imageNamed:@"right.png"];
    }else{
        titleLabel.text = @"修改失败";
        targetImageV.image = [UIImage imageNamed:@"warnning.png"];
    }
}
-(void)hidden{
    self.hidden = YES;
}
@end
